#pragma once

#include "Types.h"
#include "Button.h"
#include "Glyph.h"

#include <vector>

namespace My {

class ToolBar;

class ToolButton : public Button {
	friend class ToolBar;
public:
	enum CheckState {
		Unchecked,
		Checked,
		Indeterminate
	};
private:
	ToolBar &		m_Owner;
	unsigned int	m_Command;
	int				m_Offset;
	SysColorGlyph	m_Glyph;
	GrayedGlyph		m_Grayed;
	bool			m_Enabled;
	CheckState		m_Check;
	String			m_Hint;
public:
	virtual bool Enabled() const 
		{ return m_Enabled; }
	virtual String Hint() const 
		{ return m_Hint; }
	CheckState GetCheck() const
		{ return m_Check; }
public:
	void SetEnabled(bool on);
	void SetHint(const String & hint);
	void SetCheck(CheckState s);
	virtual void HandleClick();
public:
	ToolButton(ToolBar & owner, unsigned int cmd, const char * szGlyph);
	ToolButton(ToolBar & owner, unsigned int cmd, const char * szGlyph, const char * szMask);
	virtual CRect Bounds() const;
	virtual void HandlePaint(CDC * pDC, const CRect & r);
	virtual void HandleUpdateUI();
};

class ToolButtonCmdUI : public CCmdUI {
private:
	ToolButton &	m_Owner;
public:
	ToolButtonCmdUI(ToolButton & b)
		: m_Owner(b) { }
public:
	virtual void Enable(BOOL bOn = TRUE);
	virtual void SetCheck(int nCheck = 1);
	virtual void SetRadio(BOOL bOn = TRUE);
	virtual void SetText(LPCTSTR lpszText);
};

struct ToolButtonInfo {
	unsigned int id;
	const char * glyph;
};

class ToolBar : public Widget, public Container {
	friend class ToolButton;
public:
	enum Orientation {
		HORIZONTAL,
		VERTICAL
	};
private:
	std::vector<ToolButton *>	m_Buttons;
	Orientation					m_Orientation;
	CSize						m_ButtonSize;
	int							m_Length;
	int							m_Gap;
private:
	void UpdateButtonOffsets();
public:
	ToolBar(Orientation o);
	~ToolBar();
public:
	CSize GetButtonSize() const
		{ return m_ButtonSize; }
	int GetGap() const
		{ return m_Gap; }
	virtual CSize GetPreferredSize() const;
public:
	void SetButtons(const ToolButtonInfo items[], unsigned int count);
	void AddButton(unsigned int nID, const char * szGlyph);
	void AddButton(unsigned int nID, const char * szGlyph, const char * szMask);
	void InsertButton(My::Size pos, unsigned int nID, const char * szGlyph, const char * szMask);
	void AddSeparator();
	void SetButtonSize(CSize s);
	void SetGap(int gap);
public:
	virtual void HandlePaint(CDC * pDC, const CRect & r);
};

} // My
